package umeng

import "fmt"

//UniCastReq 单播请求参数
type UniCastReq struct {
	DeviceType  string
	DeviceToken string
	Title       string
	SubTitle    string
	Message     string
	Description string
}

//UniCast 单播
func (client *Client) UniCast(req *UniCastReq, policy *MessagePolicy) (*MessageRsp, error) {
	msgReq, err := client.getBaseReq(req.DeviceType, transTypeUnicast, policy)
	if nil != err {
		return nil, err
	}
	msgReq.DeviceTokens = req.DeviceToken

	switch req.DeviceType {
	case deviceTypeIOS:
		aps := &IOSPayLoadAPS{
			Alert: &IOSPayLoadAPSAlert{
				Title:    req.Title,
				SubTitle: req.SubTitle,
				Body:     req.Message,
			},
		}
		msgReq.Payload = map[string]interface{}{
			"aps": aps,
		}
	case deviceTypeAndroid:
		body := &AndroidPayLoadBody{
			Ticker: req.Title,
			Title:  req.Title,
			Text:   req.Message,
		}
		msgReq.Payload = &AndroidPayLoad{
			DisplayType: displayTypeNotification,
			Body:        body,
		}
	default:
		return nil, fmt.Errorf("err device type %s", req.DeviceType)
	}

	return client.send(msgReq, req.DeviceType)
}
